#include "Host.h"
#include "NodeServer.h"


CHost::CHost()
{
	m_bCacheConnOK = false;
}

CHost::~CHost()
{
}


CHostBase* CreateHost()
{
	CHost* pHost = new CHost();
	return pHost;
}

std::string GetLogFileName()
{
	return "srvmanager";
}

void CHost::Init()
{
	this->m_pNode = GetNodeServer();
	this->m_pGame = new CGameServer();
	this->m_pGame->m_pHost = this;
	this->m_pGame->InitGame();

	SpiderEvent ev;
	ev.evID = NODE_EV_SET_TYPE;
	ev.evParam.iParam = SERVER_TYPE_SERVICE_MANAGER;
	m_pNode->ProcEvent(NODE_EV_SET_TYPE, &ev);
	
	vector<CONFITEM> item;
	ev.evID = NODE_EV_SET_CACHE;
	ev.evParam.ptr = &item;
	m_pNode->ProcEvent(NODE_EV_SET_CACHE, &ev);
}


int CHost::OnBYTimeOut(int Timerid)
{
	return 0;
}

int CHost::ProcEvent(int ev_id, SpiderEvent* pEvent)
{
	if (HOST_EV_CLIENT_REGISTER == ev_id)
	{
		ServerData* pItem = (ServerData*)pEvent->evParam.ptr;
		m_pGame->ClientRegister(pItem);
	}
	else if (HOST_EV_CLIENT_CLOSE == ev_id)
	{
		SocketHandler* pHandler = (SocketHandler*)pEvent->evParam.ptr;
		m_pGame->ClientHandlerClose(pHandler);
	}
	return 0;
}

int CHost::ProcPacket(NETInputPacket* inputPkg, SocketHandler* pSocketHandler)
{
	if (NULL != m_pGame /*&& this->m_bCacheConnOK*/)
	{
		return m_pGame->ProcessPacket(pSocketHandler, inputPkg);
	}
	return 0;
}